<?php

/*
* MainModel implementation
*/

class MainModel extends Model{

	/*
	* Save questionare to database
	*/
	public function Save($questionareDTO){	
		try
		{		

	$this->db->beginTransaction();
	//new customer
	$queryCustomer = $this->db->prepare("INSERT INTO customer(name,email) VALUES(:name,:email)");
	$queryCustomer->bindParam(':name',$questionareDTO->GetUserName(),PDO::PARAM_STR);
	$queryCustomer->bindParam(':email',$questionareDTO->GetEmail(),PDO::PARAM_STR);
	$queryCustomer->execute();

	$CustomerID = $this->db->lastInsertId();

	$answersCustomer = $this->db->prepare("INSERT INTO answer(CustomerID,QuestionID,Entry) VALUES(:CustomerID,:QuestionID,:Entry)");
	
	for($i=0; $i<=10;$i++)
	{
		$answersCustomer->bindValue(':CustomerID',$CustomerID,PDO::PARAM_INT);
		$answersCustomer->bindValue(':QuestionID',$i,PDO::PARAM_INT);
		$q = 'question_'.$i;
	        $answersCustomer->bindValue(':Entry',$questionareDTO->$q);
		$answersCustomer->execute();
	}

	$this->db->commit();
	
	}catch(PDOException $e)
		{
			$this->db->rollback();
		}	
	}
	
}

?>
